import { createApp } from 'vue'
import { createPinia, storeToRefs } from "pinia";

import App from './App'
import router from './router'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' //引入持久化插件
const pinia = createPinia() //创建pinia实例
pinia.use(piniaPluginPersistedstate) //将插件添加到 pinia 实例上

import 'element-plus/dist/index.css'

import './main.less'


const app = createApp(App)

app.use(router)
app.use(pinia)

app.mount('#app')


import useUserStore from '@/stores/userStore';
const userStore = useUserStore();
const {isLogin} = storeToRefs(userStore);


router.beforeEach((to, from, next) => {
  // const password = localStorage.getItem('test_password');
  // if (!['/', 'Login'].includes(to.name as string) && password != '132511') next({ name: 'Login' })
  // else next()
  console.log('Before each navigation:', to, from, isLogin.value); // 调试日志
  if(isLogin.value){
    next();
  }else{
    if (!['/', 'Login'].includes(to.name as string)) next({ name: 'Login' })
    else next();
  }
})
